import java.io.FileInputStream;
import java.io.IOException;
import java.io.*;
//======================================================================
public class ReadFileClass {
   private  int max_vertex;
   public   int matr[][];
   private  int currentIndex = -1;
   private Integer next(String numbers[]) {
      ++currentIndex;
      while (currentIndex < numbers.length
            && numbers[currentIndex].equals(""))
         ++currentIndex;
      return currentIndex < numbers.length ? Integer
            .parseInt(numbers[currentIndex]) : null;
   }
   //======================================================================
   public int GetMaxVertex(){
       return max_vertex;
   }
   //======================================================================
   public boolean ReadFile(String filename) throws IOException {
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
       byte[] str;
       try (FileInputStream inFile = new FileInputStream(filename)) {
           str = new byte[inFile.available()];
           inFile.read(str);
           inFile.close();
           in.close();
       }
      String text = new String(str);
      String[] numbers = text.split("\\D");
      int i, j;
      if(text.length()==0){
          ErrorWin f = new ErrorWin();
          f.createGUI("Некорректный файл.");
          return false;
      }
      try {
      max_vertex = next(numbers);
      } catch(NullPointerException e) {
                            ErrorWin f = new ErrorWin();
                            f.createGUI("Некорректный файл.");
                            return false;
            }
      matr = new int[max_vertex][max_vertex];
      for (i = 0; i <max_vertex; ++i){
         for (j = 0; j <max_vertex; ++j){
            try {
            matr[i][j] = next(numbers);
            } catch(NullPointerException e) {
                            ErrorWin f = new ErrorWin();
                            f.createGUI("Некорректный файл.");
                            return false;
            }
         }
      }
      return true;
   }
}
